package com.koron.css2.workflow;

import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.mapper.PubReceiptMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.css2.workflow.bean.ProcessListBean;
import com.koron.css2.workflow.bean.ProcessListQueryBean;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;
/**
 *  我的流程列表<br>
 * 1、我发起的<br>
 * 2、我待审的（未办理、可认领、可沟通）<br>
 * 3、参与的(我发起、我已办理、我已沟通)<br>
 * 4、我已沟通的<br>
 * 5、我已办的（包含我发起和我已经办）。
 * @author admin
 *
 */
public class ProcessList implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		
		@SuppressWarnings("rawtypes")
		MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", PageInfo.class);
		try {
			ProcessListQueryBean bean = JsonUtils.objectToPojo(req.getData(), ProcessListQueryBean.class);
			String staffcode = userInfo.getUserInfo().getCode();
			bean.setOperator(staffcode);
			String companyNo = userInfo.getCurWaterCode();
			PubReceiptMapper pubMapper = factory.getMapper(PubReceiptMapper.class);
			String setCode = pubMapper.getWorkflowApp(companyNo);
			bean.setSetCode(setCode);
			PageInfo<ProcessListBean> page = WorkflowImpl.workflow(bean);
			info.setData(page);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			logger.error(e.getMessage(), e);
		}
		return info;
	}
}
